<template>
  <a-card :title="title" class="BUCBox">
    <!-- <a-button slot="extra" type='primary' @click="handleQuery">BUC状态查询</a-button> -->
    <a-descriptions size="small" :column="2" bordered style="">
      <!-- <div slot="title" style="padding: 10px 20px 0;">
                    BUC设备状态显示 <a-button type='primary' style=" float: right;">BUC状态查询</a-button>
                </div> -->
      <a-descriptions-item label="控制模式">
        {{ desData.controlModel == '0' ? '本控' : desData.controlModel == '1' ? '远控' : desData.controlModel }}
      </a-descriptions-item>
      <a-descriptions-item label="设备状态">
        {{ desData.equipmentStatus == '0' ? '正常' : desData.equipmentStatus == '1' ? '异常' : '/' }}
      </a-descriptions-item>
      <a-descriptions-item label="本振状态">
        {{ desData.localOscillatorState == '0' ? '失锁' : desData.localOscillatorState == '1' ? '锁定' : '/' }}
      </a-descriptions-item>
      <a-descriptions-item label="参考状态">
        {{
          desData.referenceStatus == '0'
            ? '内参'
            : desData.referenceStatus == '1'
            ? '外参5M'
            : desData.referenceStatus == '2'
            ? '外参10M'
            : '/'
        }}
      </a-descriptions-item>
      <a-descriptions-item label="设备类别">
        {{ desData.equipmentCategory == '0' ? '备份' : desData.equipmentCategory == '1' ? '主份' : '/' }}
      </a-descriptions-item>
      <a-descriptions-item label="衰减值(dB)">
        {{ desData.decay ? desData.decay : '/' }}
      </a-descriptions-item>
      <!-- <a-descriptions-item label="功率(dBm)">
                {{ desData.power ? Number(desData.power) / 100 : "/" }}
            </a-descriptions-item> -->
      <a-descriptions-item label="设备温度(℃)">
        {{ desData.temperature ? desData.temperature : '/' }}
      </a-descriptions-item>
      <a-descriptions-item label="输入频率(Hz)">
        {{ desData.inputFrequency ? desData.inputFrequency : '/' }}
      </a-descriptions-item>
      <a-descriptions-item label="输出频率(Hz)">
        {{ desData.outputFrequency ? desData.outputFrequency : '/' }}
      </a-descriptions-item>
      <a-descriptions-item label="TCP端口">
        {{ desData.tcpPort ? desData.tcpPort : '/' }}
      </a-descriptions-item>
      <a-descriptions-item label="IP地址">
        {{ desData.IPaddress ? desData.IPaddress : '/' }}
      </a-descriptions-item>
      <a-descriptions-item label="网关">
        {{ desData.gateway ? desData.gateway : '/' }}
      </a-descriptions-item>
      <a-descriptions-item label="子网掩码">
        {{ desData.subnetMask ? desData.subnetMask : '/' }}
      </a-descriptions-item>
      <a-descriptions-item label="MAC地址">
        {{ desData.MACaddress ? desData.MACaddress : '/' }}
      </a-descriptions-item>
    </a-descriptions>
    <!-- <a-form-model v-if="false" :model="formBUC" :label-col="labelCol" :wrapper-col="wrapperCol">
                <a-row>
                    <a-col :span=12>
                        <a-form-model-item label="频率显示(KHz)">
                            <a-input-number style="width:100%" v-model="formBUC.frequency"></a-input-number>
                        </a-form-model-item>
                    </a-col>
                    <a-col :span=12>
                        <a-form-model-item label="衰减值(dB)">
                            <a-input-number min=0 max=31 style="width:100%" v-model="formBUC.attenuator"
                                placeholder="0-31dB"></a-input-number>

                        </a-form-model-item>
                    </a-col>
                    <a-col :span=12>
                        <a-form-model-item label="定频本振锁定">
                            <a-input-number min=0 max=31 style="width:100%" v-model="formBUC.attenuator"
                                placeholder="0-31dB"></a-input-number>

                        </a-form-model-item>
                    </a-col>
                    <a-col :span=12>
                        <a-form-model-item label="跳频本振锁定">
                            <a-input-number min=0 max=31 style="width:100%" v-model="formBUC.attenuator"
                                placeholder="0-31dB"></a-input-number>

                        </a-form-model-item>
                    </a-col>
                    <a-col :span=12>
                        <a-form-model-item label="功率检测(dBm)">
                            <a-input-number min=0 max=31 style="width:100%" v-model="formBUC.attenuator"
                                placeholder="0-31dB"></a-input-number>

                        </a-form-model-item>
                    </a-col>
                </a-row>


            </a-form-model>-->
  </a-card>
</template>

<script>
import { getAction, httpAction } from '../../../api/manage'
import { mapGetters } from 'vuex'

export default {
  data() {
    return {
      formBUC: {
        powerDetection: '/',
        attenuator: '/'
      },
      labelCol: { span: 10 },
      wrapperCol: { span: 12 },
      desData: {},
      url: {
        getByChannelCode: '/attr/nmcAttr/getByChannelCode',
        list: 'nmc/activeInfo/list' //获取当前变频器是主还是备
      },
      options: [
        { resKey: 'ybk', webKey: 'controlModel', label: '控制模式' },
        { resKey: 'sbzt', webKey: 'equipmentStatus', label: '设备状态' },
        { resKey: 'bzzt', webKey: 'localOscillatorState', label: '本振状态' },
        { resKey: 'ckzt', webKey: 'referenceStatus', label: '参考状态' },
        { resKey: 'sblb', webKey: 'equipmentCategory', label: '设备类别' },
        { resKey: 'sj', webKey: 'decay', label: '衰减' },
        { resKey: 'gl', webKey: 'power', label: '功率' },
        { resKey: 'sbwd', webKey: 'temperature', label: '设备温度' },
        { resKey: 'srpl', webKey: 'inputFrequency', label: '输入频率' },
        { resKey: 'scpl', webKey: 'outputFrequency', label: '输出频率' },
        { resKey: 'tcpdk', webKey: 'tcpPort', label: 'TCP端口' },
        { resKey: 'ipdz', webKey: 'IPaddress', label: 'IP地址' },
        { resKey: 'wg', webKey: 'gateway', label: '网关' },
        { resKey: 'zwym', webKey: 'subnetMask', label: '子网掩码' },
        { resKey: 'macdz', webKey: 'MACaddress', label: 'MAC地址' }
      ],
      activeInfo: '',
      title: '变频器状态显示',
      timer: null
    }
  },
  computed: {
    ...mapGetters(['websocketMsg']),
    websocketMsg() {
      return this.$store.state.user.websocketMsg
    }
  },
  watch: {
    websocketMsg: {
      handler(val) {
        // 收到websocket的消息 则请求BUC-状态回报包,'===更换webSocket 的cmd'
        if (val) {
          let msg = JSON.parse(val)
          // if (msg.cmd === 'bpq_sx') {
          //   this.getData()
          // }
          // if(msg.cmd === 'bpq_sx') {
          //   this.getData('变频器')
          // }else if(msg.cmd === 'bpq_sx_b') {
          //   // this.getData('DCPR信道变频器(备)')
          //   this.getData('变频器备')
          // }
        }
      }
    }
  },
  mounted() {
    // this.getData()
    this.getActiveInfo()
    this.startTimer()
  },
  destroyed() {
    this.stopTimer()
  },
  methods: {
    // HandlingAlarms(val,type){
    //   let str=parseInt(val, 16).toString(2).padStart(8, '0')
    //   let arr=str.split('').reverse()
    //   let reslut=''
    //   if(type==0){
    //       reslut=arr[0]==1?"欠压":"正常"
    //   }else if(type==1){
    //       reslut=arr[1]==1?"过压":"正常"
    //   }else if(type==2){
    //       reslut=arr[2]==1?"超温":"正常"
    //   }else if(type==3){
    //       reslut=arr[3]==1?"告警":"正常"
    //   }
    //   return reslut
    // },
    getData(type) {
      let code = ''
      // if(type == '变频器' && this.activeInfo) {
      //   code = '变频器'
      // }else if(type == '变频器备' && !this.activeInfo) {
      //   code = '变频器备'
      // }
      if(this.activeInfo) {
        code = '变频器'
      }else if(!this.activeInfo) {
        code = '变频器备'
      }
      let temp = {
        channelCode: code
      }
      if (!code) return
      getAction(this.url.getByChannelCode, temp).then(res => {
        if (res.success) {
          res.result.forEach(i => {
            let key = this.options.find(j => j.resKey == i.attrName).webKey
            if (key) {
              this.$set(this.desData, key, i.parseValue)
            }
          })
        }
      })
    },
    getActiveInfo() {
      getAction(this.url.list).then(res => {
        if (res.success) {
          let id = '2'
          let list = res.result.records || []
          let info = list.find(item => item.id == id)
          if(info && info.active) {
            this.activeInfo = info.active == '主' ? true : false
            this.title = `变频器状态显示（${info.active}）`
            this.getData()
          }
        }
      })
    },
    startTimer() {
      if (this.timer) {
        clearInterval(this.timer)
      }
      this.timer = setInterval(() => {
        this.getActiveInfo()
      }, 1000)
    },
    stopTimer() {
      clearInterval(this.timer)
    },
  }
}
</script>

<style lang="less" scoped>
.BUCBox {
  height: 100%;
  overflow-y: scroll !important;
}
</style>
<style>
.BUCBox .ant-card-body {
  padding: 10px !important;
}

.ant-descriptions-bordered .ant-descriptions-item-label,
.ant-descriptions-item-content,
.ant-descriptions-title {
  background: transparent !important;
  color: #fff;
}
</style>
